#ifndef prs_FrmTable_H
#define prs_FrmTable_H

#include "prs_Rule.h"
#include "prs_FrmFunc.h"
#include "prs_FrmControl.h"
#include "prs_FrmRules.h"
#include "prs_FrmGeom.h"
#include "prs_FrmTableStyle.h"
#include "frm_control_TTable.h"

namespace prs {

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmTableCaption : public TNodeFrmControl
{
  DECLARE_ClientNode()
  //
  TAttrNodeType<nodeType_TableCaption> NodeType;
  TAttrPointerNoCopy<attrName_Control,frm::control::TTableCaption*> Control;
  //
  TNodeFrmTableCaption() : NodeType(this),Control(this) {}
  //
  void operator = (const TNodeFrmTableCaption &From) { CopyAttrFrom(&From);}
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmTableGrid : public TNodeFrmControl
{
  DECLARE_ClientNode()
  TAttrNodeType<nodeType_TableGrid> NodeType;
  TAttrPointerNoCopy<attrName_Control,frm::control::TTableGrid*> Control;
  //
  TNodeFrmTableGrid() : NodeType(this),Control(this) {}
  //
  void operator = (const TNodeFrmTableGrid &From) { CopyAttrFrom(&From);}
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmTable : public TNodeFrmControl
{
  static const char *attrName_EnLinkToFrame;
  //
  DECLARE_ClientNode()
  //
  typedef TNodeFrmTableStyle   TStyle;
  typedef frm::control::TTable TControl;
  //
  TAttrNodeType<nodeType_Table> NodeType;
  TAttrBool<attrName_EnLinkToFrame> EnLinkToFrame;
  TAttrPointerNoCopy<attrName_Control,frm::control::TTable*> Control;
  TAttrNodeObject<attrName_Caption,TNodeFrmTableCaption> Caption;
  TAttrNodeObject<attrName_Grid,TNodeFrmTableGrid> Grid;
  //
  TNodeFrmTable() : NodeType(this),EnLinkToFrame(this),Control(this),Caption(this),Grid(this) {
    EnLinkToFrame = false;
  }
 ~TNodeFrmTable() { delete Control.GetValue();}
  //
  frm::control::TTable *BuildControl(
    frm::control::TPanel *ParentControl
  );
};

///////////////////////////////////////////////////////////////////////////////

struct TRuleFrmTable : public snt::TRule
{
  TRuleFrmTable(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode,
    TRuleFrmChildrenBase &RChildren,
    TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
    TRuleSetAttrValue &RSetAttrValue,
    TRuleFrmGeom &RFrmGeom,
    TRuleSetStyle &RStyle
  );

private:  
  TNodeFrmTable *GetNodeTable() { return dynamic_cast<TNodeFrmTable*>(vParentNode.Pointer());}
  void FSetGeometryTable(snt::TParams &Params) { rGeometry.SetGeom( &GetNodeTable()->Geometry.Value );}
  //
  TNodeFrmTableCaption *GetNodeCaption() { return dynamic_cast<TNodeFrmTableCaption*>(vParentNode.Pointer());}
  void FSetCaption(snt::TParams &Params) { vParentNode = &GetNodeTable()->Caption.Value;}
  void FSetGeometryCaption(snt::TParams &Params) { rGeometry.SetGeom( &GetNodeCaption()->Geometry.Value );}
  void FSetGrid(snt::TParams &Params) { vParentNode = &GetNodeTable()->Grid.Value;}
  //
  bool FSetParam(TRuleSetAttrValue::TFuncValueIdentParams &Params);
  //
  svl::TVariant &vParentNode;
  TRuleFrmGeom &rGeometry;
  snt::TRule  RAttr,RAttr1,RCaption,RCaptionAttr,RCaptionAttr1;
  snt::TAlter AAttr1,ACaptionAttr1;
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
